package com.qf.mrmd.controller;


import com.alibaba.fastjson.JSONObject;
import com.qf.mrmd.dao.PicDao;
import com.qf.mrmd.entity.Pic;
import com.qf.mrmd.result.ResponseCode;
import com.qf.mrmd.result.ResponseData;
import com.qf.mrmd.service.PicService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController     //组合注解，表名下面类中的所有都是控制层并且返回为json格式
@RequestMapping("pics")   //路径映射
@Api("picApis")    //接口注解
public class PicController {

    @Autowired  //自动装配
    private PicService picService;                //服务层的接口对象


    /**
     *  模拟完整的添加操作
     *  1、http://localhost:8080/pics/    ---POST
     *  2、{"title":"轮播","url":"http://localhost:8080/img/a.jpg","type":"lb"}
     *  3、ResponseData   {ecode:"",info:"",data:""}
     *
     */
    @ApiOperation(value = "保存图片信息")//swagger???
    @PostMapping("/")
    public ResponseData savePicInfo(@RequestBody Pic pic){
        return picService.savePicInfo(pic);

    }

    @GetMapping("{/id}")
    @ApiImplicitParam(name = "id")
    @ApiOperation(value = "查询id")
    public ResponseData query(@RequestBody Integer id){
        Pic pic = picService.queryById(id);
        return new ResponseData(ResponseCode.SUCCESS,pic);
    }

    @PostMapping("/v")
    @ApiOperation(value = "保存数据信息")
    public ResponseData saveData(@RequestBody Pic pic){
        return picService.saveData(pic);
    }

    @ApiOperation(value = "获取轮播胡或者导航图片",notes = "通过图片的类型获取对应的图片列表")
    @ApiImplicitParam(name = "type",value = "图片的类型",dataType = "string")
    @GetMapping("/all/{type}")  //获取图片信息
    public ResponseData picInfo(@PathVariable String type){
        return picService.queryByType(type);

    }


}
